const Koa = require('koa')
const app = new Koa()

const mongoExpress = require('mongo-express/lib/middleware')
const mongoExpressConfig = require('./mongo-express-config')

app.use(async (ctx, next) => {
    await next().then(() => {
        return new Promise((resolve, reject) => {
            mongoExpress(mongoExpressConfig)(ctx.req, ctx.res, resolve)
        })
    })
})

app.use((ctx) => {
    ctx.body = 'Hello Koa in app-async.js';
});

app.listen(3000);
